package com.vrp3d.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.vrp3d.common.enums.CommonEnum;
import com.vrp3d.common.enums.CommonExceptionEnum;
import com.vrp3d.common.enums.LanguageTypeEnum;
import com.vrp3d.common.exceptions.CommonException;
import com.vrp3d.common.utils.Encodes;
import com.vrp3d.common.utils.FileUtil;
import com.vrp3d.common.utils.ObjUtil;
import com.vrp3d.common.utils.UnZipFile;
import com.vrp3d.domain.dto.LanguageDTO;
import com.vrp3d.domain.dto.booth.*;
import com.vrp3d.domain.po.Booth;
import com.vrp3d.domain.po.BoothExample;
import com.vrp3d.domain.po.Showroom;
import com.vrp3d.mapper.BoothMapper;
import com.vrp3d.service.BoothService;
import com.vrp3d.service.ShowroomService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * 展位
 *
 * @author vrp3d
 */
@Slf4j
@Service
public class BoothServiceImpl extends AbsServiceImpl implements BoothService {

    private static String fileRootPath = CommonEnum.FOLDER_ROOT.getMsg();

    @Autowired
    private ShowroomService showroomService;

    @Autowired
    private BoothMapper boothMapper;

    private BoothExample.Criteria getCriteria(BoothExample example) {
        return example.createCriteria();
    }

    private BoothExample getExample() {
        return new BoothExample();
    }

    @Override
    public String previewTheModel(String fileName) {
        String targetFilePath = fileRootPath + fileName.substring(0, fileName.lastIndexOf(CommonEnum.SEPARATOR_POINT.getMsg()));
        String s = UnZipFile.unZipFiles(fileRootPath + fileName, targetFilePath);
        return targetFilePath.substring(fileRootPath.length()) + CommonEnum.SEPARATOR_SLASH.getMsg() + s;
    }

    /**
     * 验证展厅是否存在
     *
     * @param showroomId
     */
    private void verifyThePresenceOfTheShowroom(Integer showroomId) {
        Showroom showroom = showroomService.selectByPrimaryKey(showroomId);
        if (ObjUtil.isEmpty(showroom)) {
            throw new CommonException(CommonExceptionEnum.THE_EXHIBITION_HALL_DOES_NOT_EXIST);
        }
    }

    private void insertBooth(Booth insert) {
        // 设置状态
        insert.setStatus(getNormalStatus());
        // 设置用户id
        Integer userId = getUser().getId();
        insert.setCreateId(userId);
        insert.setUpdateId(userId);
        // 设置时间
        Date date = getNowTime();
        insert.setCreateTime(date);
        insert.setUpdateTime(date);
        boothMapper.insertSelective(insert);
    }

    private void updateBooth(Booth booth, Booth update) {
        update.setId(booth.getId());
        // 设置修改人id
        update.setUpdateId(getUser().getId());
        boothMapper.updateByPrimaryKeySelective(update);
    }

    private void handleLanguage(LanguageDTO languageDTO, String chooseLanguage, String s) {
        switch (LanguageTypeEnum.getNewsEnum(chooseLanguage)) {
            case zh:
                languageDTO.setZh(s);
                break;
            case en:
                languageDTO.setEn(s);
                break;
            case ar:
                languageDTO.setAr(s);
                break;
            case ja:
                languageDTO.setJa(s);
                break;
            case ko:
                languageDTO.setKo(s);
                break;
            case es:
                languageDTO.setEs(s);
                break;
            default:
                break;
        }
    }

    @Override
    public void modifyPorcelainId(BoothPorcelainIdDTO dto) {
        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 验证展位是否已经存在
        if (ObjUtil.isEmpty(booth)) {
            // 不存在直接新增
            Booth insert = new Booth();
            BeanUtils.copyProperties(dto, insert);
            insertBooth(insert);
        } else {
            // 存在就修改
            Booth update = new Booth();
            BeanUtils.copyProperties(dto, update);
            updateBooth(booth, update);
        }
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyWorkName(BoothWorkNameDTO dto) {
        // 验证作品名称是否为空(主要是使用trim方法后)
        String workName = dto.getWorkName().trim();
        if (StringUtils.isBlank(workName)) {
            throw new CommonException(CommonExceptionEnum.WORK_NAME_CANNOT_BE_EMPTY);
        } else {
            dto.setWorkName(workName);
        }

        // 验证展厅,展位是否已经存在
        Integer boothOrder = dto.getBoothOrder();
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), boothOrder);

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 不存在直接新增
        LanguageDTO languageDTO;
        if (ObjUtil.isEmpty(booth)) {
            // 处理不同语言
            languageDTO = new LanguageDTO();
            handleLanguageWorkName(dto, insertOrUpdate, languageDTO);
            insertBooth(insertOrUpdate);
            // 存在就修改
        } else {
            // 处理不同语言
            if (StringUtils.isNotBlank(booth.getWorkName())) {
                // 原来存在
                String old = booth.getWorkName();
                languageDTO = JSON.parseObject(old, LanguageDTO.class);
            } else {
                // 原来不存在
                languageDTO = new LanguageDTO();
            }
            handleLanguageWorkName(dto, insertOrUpdate, languageDTO);
            updateBooth(booth, insertOrUpdate);
        }
    }

    private void handleLanguageWorkName(BoothWorkNameDTO dto, Booth booth, LanguageDTO languageDTO) {
        String chooseLanguage = chooseLanguage();
        String s = dto.getWorkName();
        handleLanguage(languageDTO, chooseLanguage, s);
        booth.setWorkName(JSONObject.toJSONString(languageDTO));
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyExhibitsRange(BoothExhibitsRangeDTO dto) {
        // 验证作品名称是否为空(主要是使用trim方法后)
        String exhibitsRange = dto.getExhibitsRange().trim();
        if (StringUtils.isBlank(exhibitsRange)) {
            throw new CommonException(CommonExceptionEnum.EXHIBIT_CATEGORY_CANNOT_BE_EMPTY);
        } else {
            dto.setExhibitsRange(exhibitsRange);
        }

        // 验证展厅,展位是否已经存在
        Integer boothOrder = dto.getBoothOrder();
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), boothOrder);

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 不存在直接新增
        LanguageDTO languageDTO;
        if (ObjUtil.isEmpty(booth)) {
            // 处理不同语言
            languageDTO = new LanguageDTO();
            handleLanguageExhibitsRange(dto, insertOrUpdate, languageDTO);
            insertBooth(insertOrUpdate);
            // 存在就修改
        } else {
            // 处理不同语言
            if (StringUtils.isNotBlank(booth.getExhibitsRange())) {
                // 原来存在
                String old = booth.getExhibitsRange();
                languageDTO = JSON.parseObject(old, LanguageDTO.class);
            } else {
                // 原来不存在
                languageDTO = new LanguageDTO();
            }
            handleLanguageExhibitsRange(dto, insertOrUpdate, languageDTO);
            updateBooth(booth, insertOrUpdate);
        }
    }

    private void handleLanguageExhibitsRange(BoothExhibitsRangeDTO dto, Booth booth, LanguageDTO languageDTO) {
        String chooseLanguage = chooseLanguage();
        String s = dto.getExhibitsRange();
        handleLanguage(languageDTO, chooseLanguage, s);
        booth.setExhibitsRange(JSONObject.toJSONString(languageDTO));
    }

    private void handleLanguageProductionStandard(BoothProductionStandardDTO dto, Booth booth, LanguageDTO languageDTO) {
        String chooseLanguage = chooseLanguage();
        String s = dto.getProductionStandard();
        handleLanguage(languageDTO, chooseLanguage, s);
        booth.setProductionStandard(JSONObject.toJSONString(languageDTO));
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyProductionStandard(BoothProductionStandardDTO dto) {
        // 验证作品名称是否为空(主要是使用trim方法后)
        String exhibitsRange = dto.getProductionStandard().trim();
        if (StringUtils.isBlank(exhibitsRange)) {
            throw new CommonException(CommonExceptionEnum.PRODUCTION_STANDARD_CANNOT_BE_EMPTY);
        } else {
            dto.setProductionStandard(exhibitsRange);
        }

        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 不存在直接新增
        LanguageDTO languageDTO;
        if (ObjUtil.isEmpty(booth)) {
            // 处理不同语言
            languageDTO = new LanguageDTO();
            handleLanguageProductionStandard(dto, insertOrUpdate, languageDTO);
            insertBooth(insertOrUpdate);
            // 存在就修改
        } else {
            // 处理不同语言
            if (StringUtils.isNotBlank(booth.getProductionStandard())) {
                // 原来存在
                String old = booth.getProductionStandard();
                languageDTO = JSON.parseObject(old, LanguageDTO.class);
            } else {
                // 原来不存在
                languageDTO = new LanguageDTO();
            }
            handleLanguageProductionStandard(dto, insertOrUpdate, languageDTO);
            updateBooth(booth, insertOrUpdate);
        }
    }

    private void handleLanguageAuthorName(BoothAuthorNameDTO dto, Booth booth, LanguageDTO languageDTO) {
        String chooseLanguage = chooseLanguage();
        String s = dto.getAuthorName();
        handleLanguage(languageDTO, chooseLanguage, s);
        booth.setAuthorName(JSONObject.toJSONString(languageDTO));
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyAuthorName(BoothAuthorNameDTO dto) {
        // 验证作品名称是否为空(主要是使用trim方法后)
        String authorName = dto.getAuthorName().trim();
        if (StringUtils.isBlank(authorName)) {
            throw new CommonException(CommonExceptionEnum.AUTHOR_NAME_CANNOT_BE_EMPTY);
        } else {
            dto.setAuthorName(authorName);
        }

        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 不存在直接新增
        LanguageDTO languageDTO;
        if (ObjUtil.isEmpty(booth)) {
            // 处理不同语言
            languageDTO = new LanguageDTO();
            handleLanguageAuthorName(dto, insertOrUpdate, languageDTO);
            insertBooth(insertOrUpdate);
            // 存在就修改
        } else {
            // 处理不同语言
            if (StringUtils.isNotBlank(booth.getAuthorName())) {
                // 原来存在
                String old = booth.getAuthorName();
                languageDTO = JSON.parseObject(old, LanguageDTO.class);
            } else {
                // 原来不存在
                languageDTO = new LanguageDTO();
            }
            handleLanguageAuthorName(dto, insertOrUpdate, languageDTO);
            updateBooth(booth, insertOrUpdate);
        }
    }

    private void handleLanguageShape(BoothShapeDTO dto, Booth booth, LanguageDTO languageDTO) {
        String chooseLanguage = chooseLanguage();
        String s = dto.getShape();
        handleLanguage(languageDTO, chooseLanguage, s);
        booth.setShape(JSONObject.toJSONString(languageDTO));
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyShape(BoothShapeDTO dto) {
        // 验证作品名称是否为空(主要是使用trim方法后)
        String authorName = dto.getShape().trim();
        if (StringUtils.isBlank(authorName)) {
            throw new CommonException(CommonExceptionEnum.TYPE_CANNOT_BE_EMPTY);
        } else {
            dto.setShape(authorName);
        }

        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 不存在直接新增
        LanguageDTO languageDTO;
        if (ObjUtil.isEmpty(booth)) {
            // 处理不同语言
            languageDTO = new LanguageDTO();
            handleLanguageShape(dto, insertOrUpdate, languageDTO);
            insertBooth(insertOrUpdate);
            // 存在就修改
        } else {
            // 处理不同语言
            if (StringUtils.isNotBlank(booth.getShape())) {
                // 原来存在
                String old = booth.getShape();
                languageDTO = JSON.parseObject(old, LanguageDTO.class);
            } else {
                // 原来不存在
                languageDTO = new LanguageDTO();
            }
            handleLanguageShape(dto, insertOrUpdate, languageDTO);
            updateBooth(booth, insertOrUpdate);
        }
    }

    private void handleLanguagePattern(BoothPatternDTO dto, Booth booth, LanguageDTO languageDTO) {
        String chooseLanguage = chooseLanguage();
        String s = dto.getPattern();
        handleLanguage(languageDTO, chooseLanguage, s);
        booth.setPattern(JSONObject.toJSONString(languageDTO));
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyPattern(BoothPatternDTO dto) {
        // 验证作品名称是否为空(主要是使用trim方法后)
        String authorName = dto.getPattern().trim();
        if (StringUtils.isBlank(authorName)) {
            throw new CommonException(CommonExceptionEnum.PATTERN_CANNOT_BE_EMPTY);
        } else {
            dto.setPattern(authorName);
        }

        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 不存在直接新增
        LanguageDTO languageDTO;
        if (ObjUtil.isEmpty(booth)) {
            // 处理不同语言
            languageDTO = new LanguageDTO();
            handleLanguagePattern(dto, insertOrUpdate, languageDTO);
            insertBooth(insertOrUpdate);
            // 存在就修改
        } else {
            // 处理不同语言
            if (StringUtils.isNotBlank(booth.getPattern())) {
                // 原来存在
                String old = booth.getPattern();
                languageDTO = JSON.parseObject(old, LanguageDTO.class);
            } else {
                // 原来不存在
                languageDTO = new LanguageDTO();
            }
            handleLanguagePattern(dto, insertOrUpdate, languageDTO);
            updateBooth(booth, insertOrUpdate);
        }
    }

    private void handleLanguageTechnology(BoothTechnologyDTO dto, Booth booth, LanguageDTO languageDTO) {
        String chooseLanguage = chooseLanguage();
        String s = dto.getTechnology();
        handleLanguage(languageDTO, chooseLanguage, s);
        booth.setTechnology(JSONObject.toJSONString(languageDTO));
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyTechnology(BoothTechnologyDTO dto) {
        // 验证作品名称是否为空(主要是使用trim方法后)
        String authorName = dto.getTechnology().trim();
        if (StringUtils.isBlank(authorName)) {
            throw new CommonException(CommonExceptionEnum.CRAFT_CANNOT_BE_EMPTY);
        } else {
            dto.setTechnology(authorName);
        }

        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 不存在直接新增
        LanguageDTO languageDTO;
        if (ObjUtil.isEmpty(booth)) {
            // 处理不同语言
            languageDTO = new LanguageDTO();
            handleLanguageTechnology(dto, insertOrUpdate, languageDTO);
            insertBooth(insertOrUpdate);
            // 存在就修改
        } else {
            // 处理不同语言
            if (StringUtils.isNotBlank(booth.getTechnology())) {
                // 原来存在
                String old = booth.getTechnology();
                languageDTO = JSON.parseObject(old, LanguageDTO.class);
            } else {
                // 原来不存在
                languageDTO = new LanguageDTO();
            }
            handleLanguageTechnology(dto, insertOrUpdate, languageDTO);
            updateBooth(booth, insertOrUpdate);
        }
    }

    private void handleLanguageType(BoothTypeDTO dto, Booth booth, LanguageDTO languageDTO) {
        String chooseLanguage = chooseLanguage();
        String s = dto.getType();
        handleLanguage(languageDTO, chooseLanguage, s);
        booth.setType(JSONObject.toJSONString(languageDTO));
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyType(BoothTypeDTO dto) {
        // 验证作品名称是否为空(主要是使用trim方法后)
        String authorName = dto.getType().trim();
        if (StringUtils.isBlank(authorName)) {
            throw new CommonException(CommonExceptionEnum.CATEGORY_CANNOT_BE_EMPTY);
        } else {
            dto.setType(authorName);
        }

        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 不存在直接新增
        LanguageDTO languageDTO;
        if (ObjUtil.isEmpty(booth)) {
            // 处理不同语言
            languageDTO = new LanguageDTO();
            handleLanguageType(dto, insertOrUpdate, languageDTO);
            insertBooth(insertOrUpdate);
            // 存在就修改
        } else {
            // 处理不同语言
            if (StringUtils.isNotBlank(booth.getType())) {
                // 原来存在
                String old = booth.getType();
                languageDTO = JSON.parseObject(old, LanguageDTO.class);
            } else {
                // 原来不存在
                languageDTO = new LanguageDTO();
            }
            handleLanguageType(dto, insertOrUpdate, languageDTO);
            updateBooth(booth, insertOrUpdate);
        }
    }

    private void handleLanguageMaterial(BoothMaterialDTO dto, Booth booth, LanguageDTO languageDTO) {
        String chooseLanguage = chooseLanguage();
        String s = dto.getMaterial();
        handleLanguage(languageDTO, chooseLanguage, s);
        booth.setMaterial(JSONObject.toJSONString(languageDTO));
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyMaterial(BoothMaterialDTO dto) {
        // 验证作品名称是否为空(主要是使用trim方法后)
        String authorName = dto.getMaterial().trim();
        if (StringUtils.isBlank(authorName)) {
            throw new CommonException(CommonExceptionEnum.MATERIAL_CANNOT_BE_EMPTY);
        } else {
            dto.setMaterial(authorName);
        }

        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 不存在直接新增
        LanguageDTO languageDTO;
        if (ObjUtil.isEmpty(booth)) {
            // 处理不同语言
            languageDTO = new LanguageDTO();
            handleLanguageMaterial(dto, insertOrUpdate, languageDTO);
            insertBooth(insertOrUpdate);
            // 存在就修改
        } else {
            // 处理不同语言
            if (StringUtils.isNotBlank(booth.getMaterial())) {
                // 原来存在
                String old = booth.getMaterial();
                languageDTO = JSON.parseObject(old, LanguageDTO.class);
            } else {
                // 原来不存在
                languageDTO = new LanguageDTO();
            }
            handleLanguageMaterial(dto, insertOrUpdate, languageDTO);
            updateBooth(booth, insertOrUpdate);
        }
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyHighly(BoothHighlyDTO dto) {
        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 验证展位是否已经存在
        if (ObjUtil.isEmpty(booth)) {
            // 不存在直接新增
            Booth insert = new Booth();
            BeanUtils.copyProperties(dto, insert);
            insertBooth(insert);
        } else {
            // 存在就修改
            Booth update = new Booth();
            BeanUtils.copyProperties(dto, update);
            updateBooth(booth, update);
        }
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyCal(BoothCalDTO dto) {
        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 验证展位是否已经存在
        if (ObjUtil.isEmpty(booth)) {
            // 不存在直接新增
            Booth insert = new Booth();
            BeanUtils.copyProperties(dto, insert);
            insertBooth(insert);
        } else {
            // 存在就修改
            Booth update = new Booth();
            BeanUtils.copyProperties(dto, update);
            updateBooth(booth, update);
        }
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyBellySize(BoothBellySizeDTO dto) {
        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 验证展位是否已经存在
        if (ObjUtil.isEmpty(booth)) {
            // 不存在直接新增
            Booth insert = new Booth();
            BeanUtils.copyProperties(dto, insert);
            insertBooth(insert);
        } else {
            // 存在就修改
            Booth update = new Booth();
            BeanUtils.copyProperties(dto, update);
            updateBooth(booth, update);
        }
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyBottomDiameter(BoothBottomDiameterDTO dto) {
        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 验证展位是否已经存在
        if (ObjUtil.isEmpty(booth)) {
            // 不存在直接新增
            Booth insert = new Booth();
            BeanUtils.copyProperties(dto, insert);
            insertBooth(insert);
        } else {
            // 存在就修改
            Booth update = new Booth();
            BeanUtils.copyProperties(dto, update);
            updateBooth(booth, update);
        }
    }

    private void handleLanguageConfiguration(BoothConfigurationDTO dto, Booth booth, LanguageDTO languageDTO) {
        String chooseLanguage = chooseLanguage();
        String s = dto.getConfiguration();
        handleLanguage(languageDTO, chooseLanguage, s);
        booth.setConfiguration(JSONObject.toJSONString(languageDTO));
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyConfiguration(BoothConfigurationDTO dto) {
        // 验证作品名称是否为空(主要是使用trim方法后)
        String authorName = dto.getConfiguration().trim();
        if (StringUtils.isBlank(authorName)) {
            throw new CommonException(CommonExceptionEnum.THE_CONFIGURATION_CANNOT_BE_EMPTY);
        } else {
            dto.setConfiguration(authorName);
        }

        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 不存在直接新增
        LanguageDTO languageDTO;
        if (ObjUtil.isEmpty(booth)) {
            // 处理不同语言
            languageDTO = new LanguageDTO();
            handleLanguageConfiguration(dto, insertOrUpdate, languageDTO);
            insertBooth(insertOrUpdate);
            // 存在就修改
        } else {
            // 处理不同语言
            if (StringUtils.isNotBlank(booth.getConfiguration())) {
                // 原来存在
                String old = booth.getConfiguration();
                languageDTO = JSON.parseObject(old, LanguageDTO.class);
            } else {
                // 原来不存在
                languageDTO = new LanguageDTO();
            }
            handleLanguageConfiguration(dto, insertOrUpdate, languageDTO);
            updateBooth(booth, insertOrUpdate);
        }
    }

    private void handleLanguageProcessCharacteristic(BoothProcessCharacteristicDTO dto, Booth booth, LanguageDTO languageDTO) {
        String chooseLanguage = chooseLanguage();
        String s = dto.getProcessCharacteristic();
        handleLanguage(languageDTO, chooseLanguage, s);
        booth.setProcessCharacteristic(JSONObject.toJSONString(languageDTO));
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyProcessCharacteristic(BoothProcessCharacteristicDTO dto) {
        // 验证作品名称是否为空(主要是使用trim方法后)
        String authorName = dto.getProcessCharacteristic().trim();
        if (StringUtils.isBlank(authorName)) {
            throw new CommonException(CommonExceptionEnum.CRAFT_FEATURE_CANNOT_BE_EMPTY);
        } else {
            dto.setProcessCharacteristic(authorName);
        }

        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 不存在直接新增
        LanguageDTO languageDTO;
        if (ObjUtil.isEmpty(booth)) {
            // 处理不同语言
            languageDTO = new LanguageDTO();
            handleLanguageProcessCharacteristic(dto, insertOrUpdate, languageDTO);
            insertBooth(insertOrUpdate);
            // 存在就修改
        } else {
            // 处理不同语言
            if (StringUtils.isNotBlank(booth.getProcessCharacteristic())) {
                // 原来存在
                String old = booth.getProcessCharacteristic();
                languageDTO = JSON.parseObject(old, LanguageDTO.class);
            } else {
                // 原来不存在
                languageDTO = new LanguageDTO();
            }
            handleLanguageProcessCharacteristic(dto, insertOrUpdate, languageDTO);
            updateBooth(booth, insertOrUpdate);
        }
    }

    private void handleLanguageArtisticFeatures(BoothArtisticFeaturesDTO dto, Booth booth, LanguageDTO languageDTO) {
        String chooseLanguage = chooseLanguage();
        String s = dto.getArtisticFeatures();
        handleLanguage(languageDTO, chooseLanguage, s);
        booth.setArtisticFeatures(JSONObject.toJSONString(languageDTO));
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyArtisticFeatures(BoothArtisticFeaturesDTO dto) {
        // 验证作品名称是否为空(主要是使用trim方法后)
        String authorName = dto.getArtisticFeatures().trim();
        if (StringUtils.isBlank(authorName)) {
            throw new CommonException(CommonExceptionEnum.ARTISTIC_FEATURES_CANNOT_BE_EMPTY);
        } else {
            dto.setArtisticFeatures(authorName);
        }

        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 不存在直接新增
        LanguageDTO languageDTO;
        if (ObjUtil.isEmpty(booth)) {
            // 处理不同语言
            languageDTO = new LanguageDTO();
            handleLanguageArtisticFeatures(dto, insertOrUpdate, languageDTO);
            insertBooth(insertOrUpdate);
            // 存在就修改
        } else {
            // 处理不同语言
            if (StringUtils.isNotBlank(booth.getArtisticFeatures())) {
                // 原来存在
                String old = booth.getArtisticFeatures();
                languageDTO = JSON.parseObject(old, LanguageDTO.class);
            } else {
                // 原来不存在
                languageDTO = new LanguageDTO();
            }
            handleLanguageArtisticFeatures(dto, insertOrUpdate, languageDTO);
            updateBooth(booth, insertOrUpdate);
        }
    }

    private void handleLanguageTransportation(BoothTransportationDTO dto, Booth booth, LanguageDTO languageDTO) {
        String chooseLanguage = chooseLanguage();
        String s = dto.getTransportation();
        handleLanguage(languageDTO, chooseLanguage, s);
        booth.setTransportation(JSONObject.toJSONString(languageDTO));
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyTransportation(BoothTransportationDTO dto) {
        // 验证作品名称是否为空(主要是使用trim方法后)
        String authorName = dto.getTransportation().trim();
        if (StringUtils.isBlank(authorName)) {
            throw new CommonException(CommonExceptionEnum.THE_EXHIBITOR_CANNOT_BE_EMPTY);
        } else {
            dto.setTransportation(authorName);
        }

        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 不存在直接新增
        LanguageDTO languageDTO;
        if (ObjUtil.isEmpty(booth)) {
            // 处理不同语言
            languageDTO = new LanguageDTO();
            handleLanguageTransportation(dto, insertOrUpdate, languageDTO);
            insertBooth(insertOrUpdate);
            // 存在就修改
        } else {
            // 处理不同语言
            if (StringUtils.isNotBlank(booth.getTransportation())) {
                // 原来存在
                String old = booth.getTransportation();
                languageDTO = JSON.parseObject(old, LanguageDTO.class);
            } else {
                // 原来不存在
                languageDTO = new LanguageDTO();
            }
            handleLanguageTransportation(dto, insertOrUpdate, languageDTO);
            updateBooth(booth, insertOrUpdate);
        }
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyPhone(BoothPhoneDTO dto) {
        // 验证作品名称是否为空(主要是使用trim方法后)
        String authorName = dto.getPhone().trim();
        if (StringUtils.isBlank(authorName)) {
            throw new CommonException(CommonExceptionEnum.THE_EXHIBITOR_PHONE_CANNOT_BE_EMPTY);
        } else {
            dto.setPhone(authorName);
        }

        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 验证展位是否已经存在
        if (ObjUtil.isEmpty(booth)) {
            // 不存在直接新增
            Booth insert = new Booth();
            BeanUtils.copyProperties(dto, insert);
            insertBooth(insert);
        } else {
            // 存在就修改
            Booth update = new Booth();
            BeanUtils.copyProperties(dto, update);
            updateBooth(booth, update);
        }
    }

    private void handleLanguageDockingPersonal(BoothDockingPersonalDTO dto, Booth booth, LanguageDTO languageDTO) {
        String chooseLanguage = chooseLanguage();
        String s = dto.getDockingPersonal();
        handleLanguage(languageDTO, chooseLanguage, s);
        booth.setDockingPersonal(JSONObject.toJSONString(languageDTO));
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyDockingPersonal(BoothDockingPersonalDTO dto) {
        // 验证作品名称是否为空(主要是使用trim方法后)
        String authorName = dto.getDockingPersonal().trim();
        if (StringUtils.isBlank(authorName)) {
            throw new CommonException(CommonExceptionEnum.THE_DOCKING_PERSON_CANNOT_BE_EMPTY);
        } else {
            dto.setDockingPersonal(authorName);
        }

        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 不存在直接新增
        LanguageDTO languageDTO;
        if (ObjUtil.isEmpty(booth)) {
            // 处理不同语言
            languageDTO = new LanguageDTO();
            handleLanguageDockingPersonal(dto, insertOrUpdate, languageDTO);
            insertBooth(insertOrUpdate);
            // 存在就修改
        } else {
            // 处理不同语言
            if (StringUtils.isNotBlank(booth.getDockingPersonal())) {
                // 原来存在
                String old = booth.getDockingPersonal();
                languageDTO = JSON.parseObject(old, LanguageDTO.class);
            } else {
                // 原来不存在
                languageDTO = new LanguageDTO();
            }
            handleLanguageDockingPersonal(dto, insertOrUpdate, languageDTO);
            updateBooth(booth, insertOrUpdate);
        }
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyPrice(BoothPriceDTO dto) {
        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 验证展位是否已经存在
        if (ObjUtil.isEmpty(booth)) {
            // 不存在直接新增
            Booth insert = new Booth();
            BeanUtils.copyProperties(dto, insert);
            insertBooth(insert);
        } else {
            // 存在就修改
            Booth update = new Booth();
            BeanUtils.copyProperties(dto, update);
            updateBooth(booth, update);
        }
    }

    private void handleLanguageIntroduction(BoothIntroductionDTO dto, Booth booth, LanguageDTO languageDTO) {
        String chooseLanguage = chooseLanguage();
        String s = dto.getIntroduction();
        handleLanguage(languageDTO, chooseLanguage, s);
        booth.setIntroduction(JSONObject.toJSONString(languageDTO));
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyIntroduction(BoothIntroductionDTO dto) {
        // 验证作品名称是否为空(主要是使用trim方法后)
        String authorName = dto.getIntroduction().trim();
        if (StringUtils.isBlank(authorName)) {
            throw new CommonException(CommonExceptionEnum.THE_DOCKING_PERSON_CANNOT_BE_EMPTY);
        } else {
            dto.setIntroduction(authorName);
        }

        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 不存在直接新增
        LanguageDTO languageDTO;
        if (ObjUtil.isEmpty(booth)) {
            // 处理不同语言
            languageDTO = new LanguageDTO();
            handleLanguageIntroduction(dto, insertOrUpdate, languageDTO);
            insertBooth(insertOrUpdate);
            // 存在就修改
        } else {
            // 处理不同语言
            if (StringUtils.isNotBlank(booth.getIntroduction())) {
                // 原来存在
                String old = booth.getIntroduction();
                languageDTO = JSON.parseObject(old, LanguageDTO.class);
            } else {
                // 原来不存在
                languageDTO = new LanguageDTO();
            }
            handleLanguageIntroduction(dto, insertOrUpdate, languageDTO);
            updateBooth(booth, insertOrUpdate);
        }
    }

    private void handleLanguageRemarks(BoothRemarksDTO dto, Booth booth, LanguageDTO languageDTO) {
        String chooseLanguage = chooseLanguage();
        String s = dto.getRemarks();
        handleLanguage(languageDTO, chooseLanguage, s);
        booth.setRemarks(JSONObject.toJSONString(languageDTO));
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void modifyRemarks(BoothRemarksDTO dto) {
        // 验证作品名称是否为空(主要是使用trim方法后)
        String authorName = dto.getRemarks().trim();
        if (StringUtils.isBlank(authorName)) {
            throw new CommonException(CommonExceptionEnum.REMARKS_CANNOT_BE_EMPTY);
        } else {
            dto.setRemarks(authorName);
        }

        // 验证展厅,展位是否已经存在
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());

        Booth insertOrUpdate = new Booth();
        BeanUtils.copyProperties(dto, insertOrUpdate);
        // 不存在直接新增
        LanguageDTO languageDTO;
        if (ObjUtil.isEmpty(booth)) {
            // 处理不同语言
            languageDTO = new LanguageDTO();
            handleLanguageRemarks(dto, insertOrUpdate, languageDTO);
            insertBooth(insertOrUpdate);
            // 存在就修改
        } else {
            // 处理不同语言
            if (StringUtils.isNotBlank(booth.getRemarks())) {
                // 原来存在
                String old = booth.getRemarks();
                languageDTO = JSON.parseObject(old, LanguageDTO.class);
            } else {
                // 原来不存在
                languageDTO = new LanguageDTO();
            }
            handleLanguageRemarks(dto, insertOrUpdate, languageDTO);
            updateBooth(booth, insertOrUpdate);
        }
    }

    @Override
    public void modifyAudio(BoothAudioDTO dto) {
        // 验证音频是否为空(主要是使用trim方法后)
        String audio = dto.getAudio().trim();
        if (StringUtils.isBlank(audio)) {
            throw new CommonException(CommonExceptionEnum.AUDIO_CANNOT_BE_EMPTY);
        } else {
            // 验证音频后缀
            String audioSuffix = CommonEnum.AUDIO_SUFFIX.getMsg();
            if (!audioSuffix.contains(audio.substring(audio.lastIndexOf(CommonEnum.SEPARATOR_POINT.getMsg()) + 1).toLowerCase())) {
                throw new CommonException(CommonExceptionEnum.AUDIO_SUFFIX_DOES_NOT_MEET_SPECIFICATIONS);
            }
            // 判断文件是否存在
            if (!FileUtil.fileExists(audio)) {
                throw new CommonException(CommonExceptionEnum.FILE_DOES_NOT_EXIST);
            }
            dto.setAudio(audio);
        }

        // 验证展厅是否存在(存在)
//        verifyThePresenceOfTheShowroom(dto.getShowroomId());

        // 验证展位是否已经存在
        Integer boothOrder = dto.getBoothOrder();
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), boothOrder);
        if (ObjUtil.isEmpty(booth)) {
            // 不存在,那就把新的音频复制到相应的文件夹
            String boothFileDirectory = CommonEnum.BOOTH_FILE_DIRECTORY.getMsg();
            String targetFilePath = boothFileDirectory + getFileStoragePath();
            String s = FileUtil.moveFileToDirectory(audio, targetFilePath);

            // 不存在直接新增
            Booth insert = new Booth();
            BeanUtils.copyProperties(dto, insert);
            insert.setAudio(s);
            insertBooth(insert);
        } else {
            Booth update = new Booth();
            BeanUtils.copyProperties(dto, update);
            // 存在就修改
            if (StringUtils.isNotBlank(booth.getAudio())) {
                // 判断之前是否存在音频,存在就删除旧的,移动新的到相应文件夹
                String oldAudio = booth.getAudio();

                if (oldAudio.endsWith(audio)) {
                    return;
//                    update.setAudio(null);
                } else {
                    String deleteTargetFilePath = getDeleteStoragePath();
                    FileUtil.deleteFile(oldAudio, deleteTargetFilePath);

                    String boothFileDirectory = CommonEnum.BOOTH_FILE_DIRECTORY.getMsg();
                    String targetFilePath = boothFileDirectory + getFileStoragePath();
                    String s = FileUtil.moveFileToDirectory(audio, targetFilePath);
                    update.setAudio(s);
                }
            } else {
                // 不存在,那就把新的音频复制到相应的文件夹
                String boothFileDirectory = CommonEnum.BOOTH_FILE_DIRECTORY.getMsg();
                String targetFilePath = boothFileDirectory + getFileStoragePath();
                String s = FileUtil.moveFileToDirectory(audio, targetFilePath);
                update.setAudio(s);
            }
            updateBooth(booth, update);
        }
    }

    @Override
    public void modifyModel(BoothModelDTO dto) {
        // 验证模型是否为空(主要是使用trim方法后)
        String modelZipFile = dto.getModelZipFile().trim();
        if (StringUtils.isBlank(modelZipFile)) {
            throw new CommonException(CommonExceptionEnum.MODEL_CANNOT_BE_EMPTY);
        } else {
            // 验证模型后缀
            String audioSuffix = CommonEnum.MODEL_SUFFIX.getMsg();
            if (!audioSuffix.contains(modelZipFile.substring(modelZipFile.lastIndexOf(CommonEnum.SEPARATOR_POINT.getMsg()) + 1).toLowerCase())) {
                throw new CommonException(CommonExceptionEnum.MODEL_SUFFIX_DOES_NOT_MEET_SPECIFICATIONS);
            }
            // 判断文件是否存在
            if (!FileUtil.fileExists(modelZipFile)) {
                throw new CommonException(CommonExceptionEnum.FILE_DOES_NOT_EXIST);
            }
            dto.setModelZipFile(modelZipFile);
        }

        // 验证展厅是否存在(存在)
//        verifyThePresenceOfTheShowroom(dto.getShowroomId());

        // 验证展位是否已经存在
//        Integer boothOrder = dto.getBoothOrder();
//        Booth booth = selectByBoothOrder(boothOrder);
        Booth booth = checkBoothByShowroomIdAndBoothOrder(dto.getShowroomId(), dto.getBoothOrder());
        if (ObjUtil.isEmpty(booth)) {
            // 不存在直接新增
            Booth insert = new Booth();
            BeanUtils.copyProperties(dto, insert);

            // 处理zip
            handleModelZipFile(modelZipFile, insert);

            insertBooth(insert);
        } else {
            // 存在就修改
            Booth update = new Booth();
            BeanUtils.copyProperties(dto, update);
            // 判断之前是否存在模型文件
            if (StringUtils.isNotBlank(booth.getModelFile())) {
                // 存在就删除旧的
                String oldModelFile = booth.getModelFile();
                String deleteTargetFilePath = getDeleteStoragePath();
                FileUtil.deleteFile(oldModelFile, deleteTargetFilePath);

                // 处理zip
                handleModelZipFile(modelZipFile, update);

            } else {
                // 不存在,那就把新的模型复制到相应的文件夹,并解压
                handleModelZipFile(modelZipFile, update);
            }
            updateBooth(booth, update);
        }
    }

    /**
     * 处理模型zip文件,解压
     *
     * @param modelZipFile
     * @param insert
     */
    private void handleModelZipFile(String modelZipFile, Booth insert) {
        // 移动zip文件
        String boothFileDirectory = CommonEnum.BOOTH_FILE_DIRECTORY.getMsg();
        String targetFilePath = boothFileDirectory + getFileStoragePath();
        String zipFilePath = FileUtil.moveFileToDirectory(modelZipFile, targetFilePath);
        insert.setModelZipFile(zipFilePath);

        // 解压zip
        String s = UnZipFile.unZipFiles(fileRootPath + zipFilePath, fileRootPath + zipFilePath.substring(0, zipFilePath.lastIndexOf(CommonEnum.SEPARATOR_POINT.getMsg())));
        if (StringUtils.isNotBlank(s)) {
            s = s.substring(fileRootPath.length(), s.lastIndexOf(".lh"));
        }
//        String modelFile = targetFilePath + CommonEnum.SEPARATOR_SLASH.getMsg() + s;
        insert.setModelFile(s);
    }

    @Override
    public void modifyPicture(BoothPictureDTO dto) {
//        // 验证展厅是否存在(存在)
//        verifyThePresenceOfTheShowroom(dto.getShowroomId());

        Integer boothOrder = dto.getBoothOrder();
        Integer showroomId = dto.getShowroomId();

        if (null != dto.getPictureList() && dto.getPictureList().size() > 0) {
            List<String> pictureList = dto.getPictureList();
            for (String picture : pictureList) {
                // 验证图片后缀
                String pictureSuffix = CommonEnum.PICTURE_SUFFIX.getMsg();
                if (!pictureSuffix.contains(picture.substring(picture.lastIndexOf(CommonEnum.SEPARATOR_POINT.getMsg()) + 1).toLowerCase())) {
                    throw new CommonException(CommonExceptionEnum.PICTURE_SUFFIX_DOES_NOT_MEET_SPECIFICATIONS);
                }
                // 判断文件是否存在
                if (!FileUtil.fileExists(picture)) {
                    throw new CommonException(CommonExceptionEnum.FILE_DOES_NOT_EXIST);
                }
            }
//        String pictureJsonSting = JSON.toJSONString(pictureList);

            // 验证展位是否已经存在
//            Booth booth = selectByBoothOrder(boothOrder);
            Booth booth = checkBoothByShowroomIdAndBoothOrder(showroomId, boothOrder);
            String boothFileDirectory = CommonEnum.BOOTH_FILE_DIRECTORY.getMsg();
            List<String> list = Lists.newArrayList();
            if (ObjUtil.isEmpty(booth)) {
                // 不存在直接新增,移动图片到指定位置
                for (String picture : pictureList) {
                    String targetFilePath = boothFileDirectory + getFileStoragePath();
                    String s = FileUtil.moveFileToDirectory(picture, targetFilePath);
                    list.add(s);
                }

                Booth insert = new Booth();
                BeanUtils.copyProperties(dto, insert);
                insert.setPicture(Encodes.urlEncode(JSON.toJSONString(list)));
                insertBooth(insert);
            } else {
                // 存在就修改
                if (StringUtils.isNotBlank(booth.getPicture())) {
                    // 判断之前是否存在图片,然后对比处理
                    String urlDecode = Encodes.urlDecode(booth.getPicture());
                    List<String> oldPictureList = JSONArray.parseArray(urlDecode, String.class);
                    // 遍历新的图片集合,如果老的集合中不包含,就直接复制过来
                    for (String picture : pictureList) {
                        if (!oldPictureList.contains(picture)) {
                            String targetFilePath = boothFileDirectory + getFileStoragePath();
                            String s = FileUtil.moveFileToDirectory(picture, targetFilePath);
                            list.add(s);
                        } else {
                            list.add(picture);
                        }
                    }
                    // 遍历旧的集合,如何新的中不包含就删除
                    for (String oldPicture : oldPictureList) {
                        if (!pictureList.contains(oldPicture)) {
                            String deleteTargetFilePath = getDeleteStoragePath();
                            FileUtil.deleteFile(oldPicture, deleteTargetFilePath);
                        }
                    }
                } else {
                    // 不存在直接新增,移动图片到指定位置
                    for (String picture : pictureList) {
                        String targetFilePath = boothFileDirectory + getFileStoragePath();
                        String s = FileUtil.moveFileToDirectory(picture, targetFilePath);
                        list.add(s);
                    }
                }
                Booth update = new Booth();
                BeanUtils.copyProperties(dto, update);
                update.setPicture(Encodes.urlEncode(JSON.toJSONString(list)));
                updateBooth(booth, update);
            }
        } else {
            Booth update = new Booth();
            Booth booth = checkBoothByShowroomIdAndBoothOrder(showroomId, boothOrder);
            if (ObjUtil.isNotEmpty(booth)) {
                update.setPicture("");
                updateBooth(booth, update);
            }
        }


    }

    /**
     * 查询展位信息
     *
     * @param showroomId
     * @param boothOrder
     * @return
     */
    @Override
    public BoothDTO selectBoothByShowroomIdAndBoothOrder(Integer showroomId, Integer boothOrder) {

        // 验证展厅是否存在(存在)
        Booth booth = checkBoothByShowroomIdAndBoothOrder(showroomId, boothOrder);
        if (ObjUtil.isEmpty(booth)) {
            return null;
        } else {
            BoothDTO resultDTO = new BoothDTO();
            BeanUtils.copyProperties(booth, resultDTO);
            // 处理图片
            if (StringUtils.isNotBlank(booth.getPicture())) {
                // 解码
                String pictureJsonString = booth.getPicture();
                pictureJsonString = Encodes.urlDecode(pictureJsonString);
                // json转list
                List<String> pictureList = JSONArray.parseArray(pictureJsonString, String.class);
                resultDTO.setPictureList(pictureList);
            }

            // 处理语言
            String chooseLanguage = chooseLanguage();
            // 作品名称,
            if (StringUtils.isNotBlank(resultDTO.getWorkName())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getWorkName(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setWorkName(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getExhibitsRange())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getExhibitsRange(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setExhibitsRange(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getProductionStandard())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getProductionStandard(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setProductionStandard(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getAuthorName())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getAuthorName(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setAuthorName(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getShape())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getShape(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setShape(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getPattern())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getPattern(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setPattern(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getTechnology())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getTechnology(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setTechnology(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getType())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getType(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setType(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getMaterial())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getMaterial(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setMaterial(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getConfiguration())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getConfiguration(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setConfiguration(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getProcessCharacteristic())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getProcessCharacteristic(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setProcessCharacteristic(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getArtisticFeatures())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getArtisticFeatures(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setArtisticFeatures(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getTransportation())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getTransportation(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setTransportation(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getDockingPersonal())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getDockingPersonal(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setDockingPersonal(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getRemarks())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getRemarks(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setRemarks(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getIntroduction())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getIntroduction(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setIntroduction(s);
            }
            return resultDTO;
        }
    }

    private String handleLanguage(String chooseLanguage, LanguageDTO languageDTO) {
        switch (LanguageTypeEnum.getNewsEnum(chooseLanguage)) {
            case zh:
                if (StringUtils.isNotBlank(languageDTO.getZh())) {
                    return languageDTO.getZh();
                } else {
                    return null;
                }
            case en:
                if (StringUtils.isNotBlank(languageDTO.getEn())) {
                    return languageDTO.getEn();
                } else {
                    return null;
                }
            case ar:
                if (StringUtils.isNotBlank(languageDTO.getAr())) {
                    return languageDTO.getAr();
                } else {
                    return null;
                }
            case ja:
                if (StringUtils.isNotBlank(languageDTO.getJa())) {
                    return languageDTO.getJa();
                } else {
                    return null;
                }
            case ko:
                if (StringUtils.isNotBlank(languageDTO.getKo())) {
                    return languageDTO.getKo();
                } else {
                    return null;
                }
            case es:
                if (StringUtils.isNotBlank(languageDTO.getEs())) {
                    return languageDTO.getEs();
                } else {
                    return null;
                }
            default:
                return null;
        }
    }

    @Override
    public List<Integer> echoWhetherThereIsInformationOnTheBooth(Integer showroomId) {
        // 验证展厅是否存在(存在)
        verifyThePresenceOfTheShowroom(showroomId);

        return boothMapper.echoWhetherThereIsInformationOnTheBooth(showroomId, getNormalStatus());
    }

    private Booth checkBoothByShowroomIdAndBoothOrder(Integer showroomId, Integer boothOrder) {
        // 验证展厅是否存在(存在)
        verifyThePresenceOfTheShowroom(showroomId);

        // 验证展位
        BoothExample example = getExample();
        BoothExample.Criteria criteria = getCriteria(example);
        criteria.andStatusNotEqualTo(getDeletedStatus());
        criteria.andShowroomIdEqualTo(showroomId);
        criteria.andBoothOrderEqualTo(boothOrder);
        List<Booth> list = boothMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        } else {
            return list.get(0);
        }
    }

    @Override
    public List<BoothFrontDTO> selectShowroomAllBoothByShowroomId(Integer showroomId, HttpServletRequest request) {
        // 验证展厅是否存在(存在)
        verifyThePresenceOfTheShowroom(showroomId);

        // 判断用户选择的是哪国语言(前后端自定义header参数)
        String chooseLanguage = request.getHeader(CommonEnum.USER_LANGUAGE.getMsg());
        if (StringUtils.isBlank(chooseLanguage)) {
            chooseLanguage = LanguageTypeEnum.zh.getMsg();
        }

        BoothExample example = getExample();
        BoothExample.Criteria criteria = getCriteria(example);
        criteria.andStatusEqualTo(getNormalStatus());
        criteria.andShowroomIdEqualTo(showroomId);
        List<Booth> list = boothMapper.selectByExample(example);

        // 处理参数
        List<BoothFrontDTO> result = Lists.newArrayList();
        if (!CollectionUtils.isEmpty(list) && list.size() > 0) {
            for (Booth booth : list) {
                BoothFrontDTO resultDTO = new BoothFrontDTO();
                BeanUtils.copyProperties(booth, resultDTO);
                // 处理图片
                if (StringUtils.isNotBlank(booth.getPicture())) {
                    // 解码
                    String pictureJsonString = booth.getPicture();
                    pictureJsonString = Encodes.urlDecode(pictureJsonString);
                    // json转list
                    List<String> pictureList = JSONArray.parseArray(pictureJsonString, String.class);
                    resultDTO.setPictureList(pictureList);
                }

                // 处理语言
                if (StringUtils.isNotBlank(resultDTO.getWorkName())) {
                    LanguageDTO languageDTO = JSON.parseObject(resultDTO.getWorkName(), LanguageDTO.class);
                    String s = handleLanguage(chooseLanguage, languageDTO);
                    resultDTO.setWorkName(s);
                }
                if (StringUtils.isNotBlank(resultDTO.getAuthorName())) {
                    LanguageDTO languageDTO = JSON.parseObject(resultDTO.getAuthorName(), LanguageDTO.class);
                    String s = handleLanguage(chooseLanguage, languageDTO);
                    resultDTO.setAuthorName(s);
                }
                if (StringUtils.isNotBlank(resultDTO.getShape())) {
                    LanguageDTO languageDTO = JSON.parseObject(resultDTO.getShape(), LanguageDTO.class);
                    String s = handleLanguage(chooseLanguage, languageDTO);
                    resultDTO.setShape(s);
                }
                if (StringUtils.isNotBlank(resultDTO.getPattern())) {
                    LanguageDTO languageDTO = JSON.parseObject(resultDTO.getPattern(), LanguageDTO.class);
                    String s = handleLanguage(chooseLanguage, languageDTO);
                    resultDTO.setPattern(s);
                }
                if (StringUtils.isNotBlank(resultDTO.getTechnology())) {
                    LanguageDTO languageDTO = JSON.parseObject(resultDTO.getTechnology(), LanguageDTO.class);
                    String s = handleLanguage(chooseLanguage, languageDTO);
                    resultDTO.setTechnology(s);
                }
                if (StringUtils.isNotBlank(resultDTO.getType())) {
                    LanguageDTO languageDTO = JSON.parseObject(resultDTO.getType(), LanguageDTO.class);
                    String s = handleLanguage(chooseLanguage, languageDTO);
                    resultDTO.setType(s);
                }
                if (StringUtils.isNotBlank(resultDTO.getMaterial())) {
                    LanguageDTO languageDTO = JSON.parseObject(resultDTO.getMaterial(), LanguageDTO.class);
                    String s = handleLanguage(chooseLanguage, languageDTO);
                    resultDTO.setMaterial(s);
                }
                if (StringUtils.isNotBlank(resultDTO.getConfiguration())) {
                    LanguageDTO languageDTO = JSON.parseObject(resultDTO.getConfiguration(), LanguageDTO.class);
                    String s = handleLanguage(chooseLanguage, languageDTO);
                    resultDTO.setConfiguration(s);
                }
                if (StringUtils.isNotBlank(resultDTO.getProcessCharacteristic())) {
                    LanguageDTO languageDTO = JSON.parseObject(resultDTO.getProcessCharacteristic(), LanguageDTO.class);
                    String s = handleLanguage(chooseLanguage, languageDTO);
                    resultDTO.setProcessCharacteristic(s);
                }
                if (StringUtils.isNotBlank(resultDTO.getArtisticFeatures())) {
                    LanguageDTO languageDTO = JSON.parseObject(resultDTO.getArtisticFeatures(), LanguageDTO.class);
                    String s = handleLanguage(chooseLanguage, languageDTO);
                    resultDTO.setArtisticFeatures(s);
                }
                if (StringUtils.isNotBlank(resultDTO.getTransportation())) {
                    LanguageDTO languageDTO = JSON.parseObject(resultDTO.getTransportation(), LanguageDTO.class);
                    String s = handleLanguage(chooseLanguage, languageDTO);
                    resultDTO.setTransportation(s);
                }
                if (StringUtils.isNotBlank(resultDTO.getIntroduction())) {
                    LanguageDTO languageDTO = JSON.parseObject(resultDTO.getIntroduction(), LanguageDTO.class);
                    String s = handleLanguage(chooseLanguage, languageDTO);
                    resultDTO.setIntroduction(s);
                }
                result.add(resultDTO);
            }
            return result;
        } else {
            return null;
        }
    }

    @Override
    public List<Integer> echoWhetherThereIsInformationOnTheBoothFront(Integer showroomId) {
        // 验证展厅是否存在(存在)
        verifyThePresenceOfTheShowroom(showroomId);

        return boothMapper.echoWhetherThereIsInformationOnTheBooth(showroomId, getNormalStatus());
    }

    @Override
    public BoothDTO selectBoothByShowroomIdAndBoothOrderFront(Integer showroomId, Integer boothOrder, HttpServletRequest request) {
        // 判断用户选择的是哪国语言(前后端自定义header参数)
        String chooseLanguage = request.getHeader(CommonEnum.USER_LANGUAGE.getMsg());
        if (StringUtils.isBlank(chooseLanguage)) {
            chooseLanguage = LanguageTypeEnum.zh.getMsg();
        }

        // 验证展厅是否存在(存在)
        Booth booth = checkBoothByShowroomIdAndBoothOrder(showroomId, boothOrder);
        if (ObjUtil.isEmpty(booth)) {
            return null;
        } else {
            BoothDTO resultDTO = new BoothDTO();
            BeanUtils.copyProperties(booth, resultDTO);
            // 处理图片
            if (StringUtils.isNotBlank(booth.getPicture())) {
                // 解码
                String pictureJsonString = booth.getPicture();
                pictureJsonString = Encodes.urlDecode(pictureJsonString);
                // json转list
                List<String> pictureList = JSONArray.parseArray(pictureJsonString, String.class);
                resultDTO.setPictureList(pictureList);
            }

            // 作品名称,
            if (StringUtils.isNotBlank(resultDTO.getWorkName())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getWorkName(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setWorkName(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getExhibitsRange())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getExhibitsRange(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setExhibitsRange(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getProductionStandard())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getProductionStandard(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setProductionStandard(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getAuthorName())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getAuthorName(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setAuthorName(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getShape())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getShape(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setShape(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getPattern())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getPattern(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setPattern(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getTechnology())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getTechnology(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setTechnology(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getType())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getType(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setType(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getMaterial())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getMaterial(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setMaterial(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getConfiguration())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getConfiguration(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setConfiguration(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getProcessCharacteristic())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getProcessCharacteristic(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setProcessCharacteristic(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getArtisticFeatures())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getArtisticFeatures(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setArtisticFeatures(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getTransportation())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getTransportation(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setTransportation(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getDockingPersonal())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getDockingPersonal(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setDockingPersonal(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getRemarks())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getRemarks(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setRemarks(s);
            }
            if (StringUtils.isNotBlank(resultDTO.getIntroduction())) {
                LanguageDTO languageDTO = JSON.parseObject(resultDTO.getIntroduction(), LanguageDTO.class);
                String s = handleLanguage(chooseLanguage, languageDTO);
                resultDTO.setIntroduction(s);
            }
            return resultDTO;
        }
    }
}
